package org.paradise.dms.services.impl;

import java.util.List;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.SystemUserMgrDAOImpl;
import org.paradise.dms.pojo.SystemUser;
import org.paradise.dms.pojo.SystemUserGroup;
import org.paradise.dms.pojo.SystemUserGroupRole;
import org.paradise.dms.services.SystemUserMgrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.DaoException;

@Service
public class SystemUserMgrServiceImpl implements SystemUserMgrService {
	private static Logger log = Logger.getLogger(SystemUserMgrServiceImpl.class);
	@Autowired
	private SystemUserMgrDAOImpl systemUserMgrDAO;

	public SystemUserMgrDAOImpl getSystemUserMgrDAO() {
		return systemUserMgrDAO;
	}

	public void setSystemUserMgrDAO(SystemUserMgrDAOImpl systemUserMgrDAO) {
		this.systemUserMgrDAO = systemUserMgrDAO;
	}

	/**
	 * 插入一条记录
	 */
	public boolean insertSystemUser(SystemUser systemsuer) {
		return systemUserMgrDAO.insertSystemUser(systemsuer);
	}

	public List<SystemUserGroup> getSystemUserGroupInfo() {
		return systemUserMgrDAO.findSystemUserGroupInfo();
	}

	public List<SystemUser> getSystemUserByGroupID(String systemusergroupid, int pageSize, int startRow) {
		return systemUserMgrDAO.getSystemUserByGroupID(systemusergroupid, pageSize, startRow);
	}

	public int getAGroupIDSysUserTotalRows(String systemusergroupid) throws DaoException {
		return systemUserMgrDAO.getAGroupIDSysUserTotalRows(systemusergroupid);
	}

	public String delelteSystemUserByID(String systemuserid) {
		return systemUserMgrDAO.delelteSystemUserByID(systemuserid);
	}

	public String insertSystemUserPermission(SystemUserGroupRole sugr) {
		return systemUserMgrDAO.insertSystemUserPermission(sugr);
	}

	public String updateSystemUserPermission(String systemusergroupid, String systemuserpermissionvalue) {
		return systemUserMgrDAO.updateSystemUserPermission(systemusergroupid, systemuserpermissionvalue);
	}

	public int getSystemUserGroupTotalRows() {
		return systemUserMgrDAO.getSystemUserGroupTotalRows();
	}

	public List<SystemUserGroup> listAllSysUserGroupListByPage(int pageSize, int startRow) {
		return systemUserMgrDAO.listAllSysUserGroupListByPage(pageSize, startRow);
	}

	public String deleteSysUserGroupById(String systemusergroupid) {
		return systemUserMgrDAO.deleteSysUserGroupById(systemusergroupid);
	}

	@SuppressWarnings("unchecked")
	public String updateSystemUser(SystemUser su) {
		try {
			log.info(ReflectionToStringBuilder.toString(su).toString());
			systemUserMgrDAO.update(su);
			log.info("DMS_info:更新系统用户" + ReflectionToStringBuilder.toString(su).toString() + "成功！");
			return "更新系统用户信息成功！";
		} catch (DaoException e) {
			log.info("DMS_error:更新系统用户" + ReflectionToStringBuilder.toString(su).toString() + "失败！");
			log.info("失败原因" + e);
		}
		return "更新系统用户信息失败！";
	}

	public boolean isSystemUserNameExists(String systemusername) {
		return systemUserMgrDAO.isSystemUserNameExists(systemusername);
	}
}
